home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / Menu Controls / UShapeList.cp < prev    next >
Encoding:
Text File  |  1995-06-24  |  3.2 KB  |  131 lines  |  [TEXT/MPS ]

  1. // Copyright © 1994-95 by Apple Computer, Inc. All rights reserved.
  2. // UShapeList.cp
  3.  
  4. #ifndef __USHAPELIST__
  5. #include "UShapeList.h"
  6. #endif
  7.  
  8. //========================================================================================
  9. // CLASS TShapeList
  10. //========================================================================================
  11. #undef Inherited
  12. #define Inherited TList
  13.  
  14. #pragma segment ShapeList
  15. MA_DEFINE_CLASS_M1(TShapeList, Inherited);
  16.  
  17. //----------------------------------------------------------------------------------------
  18. // TShapeList Constructor - empty
  19. //----------------------------------------------------------------------------------------
  20. #pragma segment ShapeList
  21.  
  22. TShapeList::TShapeList()
  23. {
  24. }
  25.  
  26. //----------------------------------------------------------------------------------------
  27. #pragma segment ShapeList
  28.  
  29. TShape* TShapeList::ShapeAt(ArrayIndex index)
  30. {
  31.     /* Range checking? */
  32.     return (TShape*)this->At(index);
  33. }
  34.  
  35. //----------------------------------------------------------------------------------------
  36. #pragma segment ShapeList
  37.  
  38. void TShapeList::Each(DoToShapeType DoToShape, void* staticLink)
  39. {
  40.     CShapeIterator iter(this);
  41.  
  42.     for (TShape* shape = iter.FirstShape(); iter.More(); shape = iter.NextShape())
  43.         DoToShape(shape, staticLink);
  44. }
  45.  
  46. //----------------------------------------------------------------------------------------
  47. #pragma segment ShapeList
  48.  
  49. TShape* TShapeList::FirstThat(TestShapeType TestShape, void* staticLink)
  50. {
  51.     ArrayIndex index;
  52.  
  53.     return this->IterateTil(TestShape, staticLink, kIterateForward, index);
  54. }
  55.  
  56. //----------------------------------------------------------------------------------------
  57. #pragma segment ShapeList
  58.  
  59. TShape* TShapeList::IterateTil(TestShapeType TestShape,
  60.                                void* staticLink,
  61.                                Boolean IterateForward,
  62.                                ArrayIndex& itsIndex)
  63. {
  64.     TShape* shape = NULL;
  65.  
  66.     {
  67.         CArrayIterator iter(this, IterateForward);
  68.         
  69.         for (itsIndex = iter.FirstIndex(); iter.More(); itsIndex = iter.NextIndex())
  70.         {
  71.             TShape* testShape = this->ShapeAt(itsIndex);
  72.             if (TestShape(testShape, staticLink))
  73.             {
  74.                 shape = testShape;
  75.                 break;
  76.             }
  77.         }
  78.     }
  79.  
  80.     return shape;
  81. } // TShapeList::IterateTil 
  82.  
  83. //========================================================================================
  84. // CLASS CShapeIterator
  85. //========================================================================================
  86. #pragma segment ShapeList
  87.  
  88. CShapeIterator::CShapeIterator(TShapeList* itsList, Boolean itsForward) :
  89.     CArrayIterator(itsList, itsForward)
  90. {
  91. }
  92.  
  93. CShapeIterator::CShapeIterator(TShapeList* itsList,
  94.                                 ArrayIndex itsLowBound,
  95.                                 ArrayIndex itsHighBound,
  96.                                 Boolean itsForward) :
  97.     CArrayIterator(itsList, itsLowBound, itsHighBound, itsForward)
  98. {
  99. }
  100.  
  101. TShape* CShapeIterator::CurrentShape()
  102. {
  103.     if (this->More())
  104.         return ((TShapeList *)fDynamicArray)->ShapeAt(fCurrentIndex);
  105.     else
  106.         return NULL;
  107. }
  108.  
  109. TShape* CShapeIterator::FirstShape()
  110. {
  111.     this->Reset();
  112.     if (this->More())
  113.         return ((TShapeList *)fDynamicArray)->ShapeAt(fCurrentIndex);
  114.     else
  115.         return NULL;
  116. }
  117.  
  118. TShape* CShapeIterator::NextShape()
  119. {
  120.     this->Advance();
  121.     if (this->More())
  122.         return ((TShapeList *)fDynamicArray)->ShapeAt(fCurrentIndex);
  123.     else
  124.         return NULL;
  125. }
  126.  
  127. CShapeIterator::~CShapeIterator()
  128. {
  129. }
  130.  
  131.